from apps.users.models import ChatMessage, User, Teacher
from apps.users.serializers import TeacherUserModelSerializer
from utils.models import BaseModelSerializer
from rest_framework import serializers


class ChatMessageModelSerializer(BaseModelSerializer):
    receiver_id = serializers.IntegerField()
    receiver = serializers.CharField()
    sender_id = serializers.IntegerField()
    sender = serializers.CharField()

    class Meta:
        model = ChatMessage
        fields = '__all__'


class SystemMessageModelSerializer(BaseModelSerializer):
    sender = TeacherUserModelSerializer()
    receiver = TeacherUserModelSerializer()

    class Meta:
        model = ChatMessage
        fields = '__all__'


class RecentContactsUserModelSerializer(BaseModelSerializer):
    unread_message = serializers.IntegerField()
    newest_message = serializers.CharField()
    newest_create_time = serializers.DateTimeField()
    teacher = serializers.StringRelatedField()

    class Meta:
        model = User
        fields = (
            'decorate_avatar', 'username', 'id', 'unread_message', 'newest_message', 'newest_create_time', 'teacher')
        read_only_fields = (
            'decorate_avatar', 'username', 'id', 'unread_message', 'newest_message', 'newest_create_time', 'teacher')
